package com.apollographql.apollo.api;

import com.apollographql.apollo.api.internal.ResponseFieldMarshaller;
import com.apollographql.apollo.subscription.OperationServerMessage;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.kt.Metadata;
import com.kt.Unit;
import com.kt.jvm.functions.Function2;
import com.kt.jvm.internal.Intrinsics;

@Metadata(bv = {1, 0, 3}, d1 = {"\u0000f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010%\n\u0002\u0010\u000e\n\u0002\u0010\u0000\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0006\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0004\n\u0002\u0010 \n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0005\u0018\u00002\u00020\u0001:\u0001(B\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\u0010\u0010\t\u001a\u00020\u00072\b\u0010\n\u001a\u0004\u0018\u00010\u0007J\u001f\u0010\u000b\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\u000e2\b\u0010\u000f\u001a\u0004\u0018\u00010\u0010H\u0016¢\u0006\u0002\u0010\u0011J\u001a\u0010\u0012\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\u00132\b\u0010\u000f\u001a\u0004\u0018\u00010\bH\u0016J\u001f\u0010\u0014\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\u000e2\b\u0010\u000f\u001a\u0004\u0018\u00010\u0015H\u0016¢\u0006\u0002\u0010\u0016J\u0012\u0010\u0017\u001a\u00020\f2\b\u0010\u0018\u001a\u0004\u0018\u00010\u0019H\u0016J\u001f\u0010\u001a\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\u000e2\b\u0010\u000f\u001a\u0004\u0018\u00010\u001bH\u0016¢\u0006\u0002\u0010\u001cJ4\u0010\u001d\u001a\u00020\f\"\u0004\b\u0000\u0010\u001e2\u0006\u0010\r\u001a\u00020\u000e2\u000e\u0010\u001f\u001a\n\u0012\u0004\u0012\u0002H\u001e\u0018\u00010 2\f\u0010!\u001a\b\u0012\u0004\u0012\u0002H\u001e0\"H\u0016J\u001f\u0010#\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\u000e2\b\u0010\u000f\u001a\u0004\u0018\u00010$H\u0016¢\u0006\u0002\u0010%J\u001a\u0010&\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\u000e2\b\u0010\u0018\u001a\u0004\u0018\u00010\u0019H\u0016J\u001a\u0010'\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\u000e2\b\u0010\u000f\u001a\u0004\u0018\u00010\u0007H\u0016R\u001c\u0010\u0005\u001a\u0010\u0012\u0004\u0012\u00020\u0007\u0012\u0006\u0012\u0004\u0018\u00010\b0\u0006X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0003X\u0004¢\u0006\u0002\n\u0000¨\u0006)"}, d2 = {"Lcom/apollographql/apollo/api/internal/SimpleResponseWriter;", "Lcom/apollographql/apollo/api/internal/ResponseWriter;", "scalarTypeAdapters", "Lcom/apollographql/apollo/api/ScalarTypeAdapters;", "(Lcom/apollographql/apollo/api/ScalarTypeAdapters;)V", OperationServerMessage.Data.TYPE, "", "", "", "toJson", "indent", "writeBoolean", "", "field", "Lcom/apollographql/apollo/api/ResponseField;", "value", "", "(Lcom/apollographql/apollo/api/ResponseField;Ljava/lang/Boolean;)V", "writeCustom", "Lcom/apollographql/apollo/api/ResponseField$CustomTypeField;", "writeDouble", "", "(Lcom/apollographql/apollo/api/ResponseField;Ljava/lang/Double;)V", "writeFragment", "marshaller", "Lcom/apollographql/apollo/api/internal/ResponseFieldMarshaller;", "writeInt", "", "(Lcom/apollographql/apollo/api/ResponseField;Ljava/lang/Integer;)V", "writeList", "T", "values", "", "listWriter", "Lcom/apollographql/apollo/api/internal/ResponseWriter$ListWriter;", "writeLong", "", "(Lcom/apollographql/apollo/api/ResponseField;Ljava/lang/Long;)V", "writeObject", "writeString", "CustomListItemWriter", "apollo-api"}, k = 1, mv = {1, 4, 0})
/* compiled from: SimpleResponseWriter.kt */
public final class SimpleResponseWriter implements ResponseWriter {
    private final Map<String, Object> data = new LinkedHashMap();
    private final ScalarTypeAdapters scalarTypeAdapters;

    public SimpleResponseWriter(ScalarTypeAdapters scalarTypeAdapters2) {
        Intrinsics.checkParameterIsNotNull(scalarTypeAdapters2, "scalarTypeAdapters");
        this.scalarTypeAdapters = scalarTypeAdapters2;
    }

    @Override // com.apollographql.apollo.api.ResponseWriter
    public <T> void writeList(ResponseField field, List<? extends T> list, Function2<? super List<? extends T>, ? super ListItemWriter, Unit> function2) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        Intrinsics.checkParameterIsNotNull(function2, "block");
        DefaultImpls.writeList(this, field, list, function2);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:11:0x0048, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:12:0x004a, code lost:
        if (r3 != null) goto L_0x004e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:14:?, code lost:
        r3.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:16:0x0054, code lost:
        throw r0;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final String toJson(String r10) throws java.io.IOException {
        /*
            r9 = this;
            okio.Buffer r0 = new okio.Buffer
            r0.<init>()
            r1 = r0
            r2 = 0
            com.apollographql.apollo.api.internal.json.JsonWriter$Companion r3 = com.apollographql.apollo.api.internal.json.JsonWriter.Companion
            r4 = r1
            okio.BufferedSink r4 = (okio.BufferedSink) r4
            com.apollographql.apollo.api.internal.json.JsonWriter r3 = r3.of(r4)
            java.io.Closeable r3 = (java.io.Closeable) r3
            r4 = 0
            r5 = 0
            java.lang.Throwable r5 = (java.lang.Throwable) r5
            r6 = r3
            com.apollographql.apollo.api.internal.json.JsonWriter r6 = (com.apollographql.apollo.api.internal.json.JsonWriter) r6     // Catch:{ all -> 0x0044 }
            r7 = 0
            r6.setIndent(r10)     // Catch:{ all -> 0x0044 }
            r6.beginObject()     // Catch:{ all -> 0x0044 }
            java.lang.String r8 = "data"
            r6.name(r8)     // Catch:{ all -> 0x0044 }
            java.util.Map<java.lang.String, java.lang.Object> r8 = r9.data     // Catch:{ all -> 0x0044 }
            com.apollographql.apollo.api.internal.json.Utils.writeToJson(r8, r6)     // Catch:{ all -> 0x0044 }
            r6.endObject()     // Catch:{ all -> 0x0044 }
            com.kt.Unit r6 = com.kt.Unit.INSTANCE     // Catch:{ all -> 0x0044 }
            if (r3 != 0) goto L_0x0037
            goto L_0x003a
        L_0x0037:
            r3.close()
        L_0x003a:
            java.lang.String r0 = r0.readUtf8()
            return r0
        L_0x0044:
            r0 = move-exception
            r5 = r0
            throw r0     // Catch:{ all -> 0x0048 }
        L_0x0048:
            r0 = move-exception
            if (r3 == 0) goto L_0x0053
            r3.close()     // Catch:{ all -> 0x0052 }
            goto L_0x0053
        L_0x0052:
            r6 = move-exception
        L_0x0053:
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.apollographql.apollo.api.SimpleResponseWriter.toJson(java.lang.String):java.lang.String");
    }

    @Override // com.apollographql.apollo.api.ResponseWriter
    public void writeString(ResponseField field, String value) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        this.data.put(field.getResponseName(), value);
    }

    @Override // com.apollographql.apollo.api.ResponseWriter
    public void writeInt(ResponseField field, Integer value) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        this.data.put(field.getResponseName(), value);
    }

    @Override // com.apollographql.apollo.api.ResponseWriter
    public void writeLong(ResponseField field, Long value) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        this.data.put(field.getResponseName(), value);
    }

    @Override // com.apollographql.apollo.api.ResponseWriter
    public void writeDouble(ResponseField field, Double value) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        this.data.put(field.getResponseName(), value);
    }

    @Override // com.apollographql.apollo.api.ResponseWriter
    public void writeBoolean(ResponseField field, Boolean value) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        this.data.put(field.getResponseName(), value);
    }

    @Override // com.apollographql.apollo.api.ResponseWriter
    public void writeCustom(ResponseField.CustomTypeField field, Object value) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        if (value == null) {
            this.data.put(field.getResponseName(), null);
            return;
        }
        this.data.put(field.getResponseName(), this.scalarTypeAdapters.adapterFor(field.getScalarType()).encode(value).value);
    }

    @Override // com.apollographql.apollo.api.ResponseWriter
    public void writeObject(ResponseField field, ResponseFieldMarshaller marshaller) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        if (marshaller == null) {
            this.data.put(field.getResponseName(), null);
            return;
        }
        SimpleResponseWriter objectResponseWriter = new SimpleResponseWriter(this.scalarTypeAdapters);
        marshaller.marshal(objectResponseWriter);
        this.data.put(field.getResponseName(), objectResponseWriter.data);
    }

    @Override // com.apollographql.apollo.api.ResponseWriter
    public void writeFragment(ResponseFieldMarshaller marshaller) {
        if (marshaller != null) {
            marshaller.marshal(this);
        }
    }

    @Override // com.apollographql.apollo.api.ResponseWriter
    public <T> void writeList(ResponseField field, List<? extends T> list, ListWriter<T> listWriter) {
        Intrinsics.checkParameterIsNotNull(field, "field");
        Intrinsics.checkParameterIsNotNull(listWriter, "listWriter");
        if (list == null) {
            this.data.put(field.getResponseName(), null);
            return;
        }
        CustomListItemWriter listItemWriter = new CustomListItemWriter(this.scalarTypeAdapters);
        listWriter.write(list, listItemWriter);
        this.data.put(field.getResponseName(), listItemWriter.getData$apollo_api());
    }

    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0006\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0004\n\u0002\u0010 \n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\b\u0002\u0018\u00002\u00020\u0001B\u000f\b\u0000\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\u0017\u0010\u000b\u001a\u00020\f2\b\u0010\r\u001a\u0004\u0018\u00010\u000eH\u0016¢\u0006\u0002\u0010\u000fJ\u001a\u0010\u0010\u001a\u00020\f2\u0006\u0010\u0011\u001a\u00020\u00122\b\u0010\r\u001a\u0004\u0018\u00010\u0007H\u0016J\u0017\u0010\u0013\u001a\u00020\f2\b\u0010\r\u001a\u0004\u0018\u00010\u0014H\u0016¢\u0006\u0002\u0010\u0015J\u0017\u0010\u0016\u001a\u00020\f2\b\u0010\r\u001a\u0004\u0018\u00010\u0017H\u0016¢\u0006\u0002\u0010\u0018J,\u0010\u0019\u001a\u00020\f\"\u0004\b\u0000\u0010\u001a2\u000e\u0010\u001b\u001a\n\u0012\u0004\u0012\u0002H\u001a\u0018\u00010\u001c2\f\u0010\u001d\u001a\b\u0012\u0004\u0012\u0002H\u001a0\u001eH\u0016J\u0017\u0010\u001f\u001a\u00020\f2\b\u0010\r\u001a\u0004\u0018\u00010 H\u0016¢\u0006\u0002\u0010!J\u0012\u0010\"\u001a\u00020\f2\b\u0010#\u001a\u0004\u0018\u00010$H\u0016J\u0012\u0010%\u001a\u00020\f2\b\u0010\r\u001a\u0004\u0018\u00010&H\u0016R(\u0010\u0005\u001a\u0016\u0012\u0006\u0012\u0004\u0018\u00010\u00070\u0006j\n\u0012\u0006\u0012\u0004\u0018\u00010\u0007`\bX\u0004¢\u0006\b\n\u0000\u001a\u0004\b\t\u0010\nR\u000e\u0010\u0002\u001a\u00020\u0003X\u0004¢\u0006\u0002\n\u0000¨\u0006'"}, d2 = {"Lcom/apollographql/apollo/api/internal/SimpleResponseWriter$CustomListItemWriter;", "Lcom/apollographql/apollo/api/internal/ResponseWriter$ListItemWriter;", "scalarTypeAdapters", "Lcom/apollographql/apollo/api/ScalarTypeAdapters;", "(Lcom/apollographql/apollo/api/ScalarTypeAdapters;)V", OperationServerMessage.Data.TYPE, "Ljava/util/ArrayList;", "", "Lkotlin/collections/ArrayList;", "getData$apollo_api", "()Ljava/util/ArrayList;", "writeBoolean", "", "value", "", "(Ljava/lang/Boolean;)V", "writeCustom", "scalarType", "Lcom/apollographql/apollo/api/ScalarType;", "writeDouble", "", "(Ljava/lang/Double;)V", "writeInt", "", "(Ljava/lang/Integer;)V", "writeList", "T", "items", "", "listWriter", "Lcom/apollographql/apollo/api/internal/ResponseWriter$ListWriter;", "writeLong", "", "(Ljava/lang/Long;)V", "writeObject", "marshaller", "Lcom/apollographql/apollo/api/internal/ResponseFieldMarshaller;", "writeString", "", "apollo-api"}, k = 1, mv = {1, 4, 0})
    /* compiled from: SimpleResponseWriter.kt */
    private static final class CustomListItemWriter implements ListItemWriter {
        private final ArrayList<Object> data = new ArrayList<>();
        private final ScalarTypeAdapters scalarTypeAdapters;

        public CustomListItemWriter(ScalarTypeAdapters scalarTypeAdapters2) {
            Intrinsics.checkParameterIsNotNull(scalarTypeAdapters2, "scalarTypeAdapters");
            this.scalarTypeAdapters = scalarTypeAdapters2;
        }

        @Override // com.apollographql.apollo.api.ResponseWriter.ListItemWriter
        public <T> void writeList(List<? extends T> list, Function2<? super List<? extends T>, ? super ListItemWriter, Unit> function2) {
            Intrinsics.checkParameterIsNotNull(function2, "block");
            DefaultImpls.writeList(this, list, function2);
        }

        public final ArrayList<Object> getData$apollo_api() {
            return this.data;
        }

        @Override // com.apollographql.apollo.api.ResponseWriter.ListItemWriter
        public void writeString(String value) {
            this.data.add(value);
        }

        @Override // com.apollographql.apollo.api.ResponseWriter.ListItemWriter
        public void writeInt(Integer value) {
            this.data.add(value);
        }

        @Override // com.apollographql.apollo.api.ResponseWriter.ListItemWriter
        public void writeLong(Long value) {
            this.data.add(value);
        }

        @Override // com.apollographql.apollo.api.ResponseWriter.ListItemWriter
        public void writeDouble(Double value) {
            this.data.add(value);
        }

        @Override // com.apollographql.apollo.api.ResponseWriter.ListItemWriter
        public void writeBoolean(Boolean value) {
            this.data.add(value);
        }

        @Override // com.apollographql.apollo.api.ResponseWriter.ListItemWriter
        public void writeCustom(ScalarType scalarType, Object value) {
            Intrinsics.checkParameterIsNotNull(scalarType, "scalarType");
            if (value == null) {
                this.data.add(null);
                return;
            }
            this.data.add(this.scalarTypeAdapters.adapterFor(scalarType).encode(value).value);
        }

        @Override // com.apollographql.apollo.api.ResponseWriter.ListItemWriter
        public void writeObject(ResponseFieldMarshaller marshaller) {
            if (marshaller == null) {
                this.data.add(null);
                return;
            }
            SimpleResponseWriter objectResponseWriter = new SimpleResponseWriter(this.scalarTypeAdapters);
            marshaller.marshal(objectResponseWriter);
            this.data.add(objectResponseWriter.data);
        }

        @Override // com.apollographql.apollo.api.ResponseWriter.ListItemWriter
        public <T> void writeList(List<? extends T> list, ListWriter<T> listWriter) {
            Intrinsics.checkParameterIsNotNull(listWriter, "listWriter");
            if (list == null) {
                this.data.add(null);
                return;
            }
            CustomListItemWriter listItemWriter = new CustomListItemWriter(this.scalarTypeAdapters);
            listWriter.write(list, listItemWriter);
            this.data.add(listItemWriter.data);
        }
    }
}
